home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Development
/
Source
/
MSG Graphic Effects 1.0 Source
/
Dissolve wipe.c
< prev
next >
Wrap
Text File
|
1993-08-21
|
4KB
|
121 lines
/*******************************************************************************
* Copywrite © 1992-1993 David S. Blumenthal *
* *
* This file is provided as is, and may be freely distributed unaltered. This *
* message must accompany any copy of this file. This file may be used or *
* modified for use for a non-commercial product provided that appropriate *
* credit is given to the author named above. *
* Commercial use of this source code is prohibited. *
******************************************************************************/
#include "msg misc.h"
#include "msg timing.h"
#define CorrectTime 2
void DissolveBox(GrafPtr, Rect*, Rect*);
void DissolveWipe(GrafPtr);
void DissolveBox(GrafPtr newImage, Rect *source, Rect *dest)
{
long offRowBytes, sizeOfOff;
Ptr myBits;
Rect bRect;
GrafPort myGrafPort;
GrafPtr myGrafPtr;
RgnHandle oldClipRgn;
int i, j;
Pattern thePattern;
char order[16];
long randtemp;
char ordertemp;
/* the dissolve effect works by creating a random set of patterns which sum
(OR) to a black pattern. We make another offscreen bitmap and fill it with
the pattern at each stage, and use it as a mask for the bitcopy. Here, we
create the offscreen bitmap. */
SetPort(newImage);
bRect = *source;
myGrafPtr = &myGrafPort;
OpenPort(myGrafPtr);
offRowBytes = (((source->right - source->left) + 15) >> 4) << 1;
sizeOfOff = (long)(source->bottom - source->top) * offRowBytes;
OffsetRect(&bRect, -bRect.left, -bRect.top);
myBits = NewPtr(sizeOfOff);
if(myBits == 0L)
ErrorString("\pThere is not enough memory. ", "\p");
myGrafPort.portBits.baseAddr = myBits;
myGrafPort.portBits.rowBytes = offRowBytes;
myGrafPort.portBits.bounds = bRect;
myGrafPort.portRect = bRect;
oldClipRgn = myGrafPort.clipRgn;
myGrafPort.clipRgn = gMainWindow->visRgn;
for(i = 0; i < 16; i++)
order[i] = i;
/* this randomly shuffles the order in which the pattern bits will appear */
for(i = 15; i >= 0; i--) {
randtemp = (((long)Random() + 32767) * (i + 1)) / 65535;
ordertemp = order[randtemp];
order[randtemp] = order[i];
order[i] = ordertemp;
}
for(i = 0; i < 16; i++)
{
StartTiming();
SetPort(myGrafPtr);
for(j = 0; j < 8; j++) thePattern[j] = 0;
thePattern[order[i] >> 2] = 1 << (order[i] & 0x03);
thePattern[order[i] >> 2] |= 16 << (order[i] & 0x03);
thePattern[(order[i] >> 2) + 4] = 1 << (order[i] & 0x03);
thePattern[(order[i] >> 2) + 4] |= 16 << (order[i] & 0x03);
FillRect(&bRect, &thePattern);
SetPort(gMainWindow);
CopyMask(&(newImage->portBits), &(myGrafPtr->portBits),
&(gMainWindow->portBits), source, &bRect, dest);
TimeCorrection(CorrectTime);
}
myGrafPort.clipRgn = oldClipRgn;
ClosePort(myGrafPtr);
DisposPtr(myBits);
}
/* the actual dissolve wipe splits the screen into 9 blocks, and dissolves
the source onto the destination by blocks in random order. That way, each
dissolve is faster, and the whole effect is more interesting. */
void DissolveWipe(GrafPtr myGrafPtr)
{
char order[9];
char ordertemp;
int i;
long randtemp;
Rect source, dest;
for(i = 0; i < 9; i++)
order[i] = i;
for(i = 8; i >= 0; i--) {
randtemp = (((long)Random() + 32767) * (i + 1)) / 65535;
ordertemp = order[randtemp];
order[randtemp] = order[i];
order[i] = ordertemp;
}
for(i = 0; i < 9; i++) {
source.top = (order[i] / 3) * (MAIN_WINDOW_HEIGHT / 3);
source.left = (order[i] % 3) * (MAIN_WINDOW_WIDTH / 3);
source.bottom = (((order[i] / 3) + 1) * MAIN_WINDOW_HEIGHT) / 3;
source.right = (((order[i] % 3) + 1) * MAIN_WINDOW_WIDTH) / 3;
DissolveBox(myGrafPtr, &source, &source);
}
}